<?php

/**
 * Created by novebeta.
 * Date: 10/19/12
 * Time: 7:14 PM
 */
class u {

    static public function menuAdmin() {
        return array(
            array(
                'label' => 'Slide Home',
                'url' => array('slidehome/admin'),
                'visible' => app()->user->isHaveAccess(),),
            array(
                'label' => 'Konten',
                'url' => array('#'),
                'visible' => app()->user->isHaveAccess(),
                'items' => array(
                    array('label' => 'Artikel',
                        'url' => array('artikel/admin'),
                        'visible' => app()->user->isHaveAccess(),
                        'items' => array(
                            array('label' => 'Tambah Artikel', 'url' => array('artikel/create')),
                            array('label' => 'Daftar Artikel', 'url' => array('artikel/admin')),
                            array('label' => 'Komentar Artikel', 'url' => array(
                                    'bukutamuArtikel/admin')),)
                    ),
                    array(
                        'label' => 'Aturan Kelompok',
                        'url' => array('aturan/admin'),
                        'visible' => app()->user->isHaveAccess(),
                        'items' => array(
                            array('label' => 'Tambah Aturan Kelompok', 'url' => array(
                                    'aturan/create')),
                            array('label' => 'Daftar Aturan Kelompok', 'url' => array(
                                    'aturan/admin')),)),
                    array(
                        'label' => 'Kajian',
                        'url' => array('kajian/admin'),
                        'visible' => app()->user->isHaveAccess(),
                        'items' => array(
                            array('label' => 'Tambah Artikel', 'url' => array('kajian/create')),
                            array('label' => 'Daftar Artikel', 'url' => array('kajian/admin')),
                            array('label' => 'Komentar Fiqih', 'url' => array('bukutamuFiqih/admin')),
                            array('label' => 'Komentar Tasawuf', 'url' => array(
                                    'bukutamuTasawuf/admin')),)),
                    array(
                        'label' => 'Berita',
                        'url' => array('berita/admin'),
                        'visible' => app()->user->isHaveAccess(),
                        'items' => array(
                            array('label' => 'Tambah Berita', 'url' => array('berita/create')),
                            array('label' => 'Daftar Berita', 'url' => array('berita/admin')),
                            array('label' => 'Komentar Berita', 'url' => array('bukutamuBerita/admin')),
                        // array('label' => 'Tambah Kategori Berita', 'url' => array('berita/createkategori')),
                        //array('label' => 'Daftar Kategori Berita', 'url' => array('berita/adminkategori')),
                        )),
                    array(
                        'label' => 'Struktur Organisasi',
                        'visible' => app()->user->isHaveAccess(),
                        'url' => array('struktur/admin'), //'items' => array(
                    //                        array('label' => 'Kabupaten', 'url' => array('kabupatenanggota/create')),
                    //                        array('label' => 'Kecamatan', 'url' => array('kecamatananggota/admin')),
                    //                        array('label' => 'Desa', 'url' => array('desaanggota/admin')),
                    //                    )
                    ),
                    array(
                        'label' => 'Tanya Jawab',
                        'url' => array('bukutamu/admin'),
                        'visible' => app()->user->isHaveAccess(),),
                    array(
                        'label' => 'Galeri',
                        'url' => array('galeri/admin'),
                        'visible' => app()->user->isHaveAccess(),
                        'items' => array(
                            array('label' => 'Tambah Galeri', 'url' => array('galeri/create')),
                            array('label' => 'Daftar Galeri', 'url' => array('galeri/admin')),)),
                    array(
                        'label' => 'Jamaah',
                        'url' => array('jamaah/admin'),
                        'items' => array(
                            array('label' => 'Tambah Jamaah', 'url' => array('jamaah/create')),
                            array('label' => 'Daftar Jamaah', 'url' => array('jamaah/admin')),
                            array(
                                'label' => 'Import Jamaah',
                                'url' => array('jamaah/import'),
                                'visible' => app()->user->isHaveAccess()),)),
                    array(
                        'label' => 'Pengajian',
                        'url' => array('pengajian/admin'),
                        'items' => array(
                            array('label' => 'Tambah Pengajian', 'url' => array(
                                    'pengajian/create')),
                            array('label' => 'Daftar Pengajian', 'url' => array(
                                    'pengajian/admin')),)),
                    array(
                        'label' => 'Kelompok',
                        'url' => array('kelompok/admin'),
                        'items' => array(
                            array('label' => 'Tambah Kelompok', 'url' => array('kelompok/create')),
                            array('label' => 'Daftar Kelompok', 'url' => array('kelompok/admin')),)),
                    array(
                        'label' => 'Wilayah',
                        'url' => array('kabupaten/admin'),
                        'visible' => app()->user->isHaveAccess(array(LevelUser::ASWIL,
                            LevelUser::SUPERADMIN)),
                        'items' => array(
                            array('label' => 'Tambah Kabupaten', 'url' => array(
                                    'kabupaten/create')),
                            array('label' => 'Daftar Kabupaten/ Tambah Pengurus',
                                'url' => array(
                                    'kabupaten/admin')),
                            array('label' => 'Tambah Kecamatan', 'url' => array(
                                    'kecamatan/create')),
                            array('label' => 'Daftar Kecamatan/ Tambah Pengurus ',
                                'url' => array(
                                    'kecamatan/admin')),
                            array('label' => 'Tambah Kelurahan', 'url' => array(
                                    'kelurahan/create')),
                            array('label' => 'Daftar Kelurahan/ Tambah Pengurus',
                                'url' => array(
                                    'kelurahan/admin')),
                            array('label' => 'Tambah Desa', 'url' => array('desa/create')),
                            array('label' => 'Daftar Desa/ Tambah Pengurus', 'url' => array(
                                    'desa/admin')),)),
                )
            ),
            /*  array(
              'label' => 'Artikel',
              'url' => array('artikel/admin'),
              'visible' => app()->user->isHaveAccess(),
              'items' => array(
              array('label' => 'Tambah Artikel', 'url' => array('artikel/create')),
              array('label' => 'Daftar Artikel', 'url' => array('artikel/admin')),
              array('label' => 'Komentar Artikel', 'url' => array('bukutamuArtikel/admin')),)), */
            array(
                'label' => 'Halaman',
                'url' => url('page/admin', array('id' => 1)),
                'visible' => app()->user->isHaveAccess(),
                'items' => array(
                    array('label' => 'Tambah Halaman', 'url' => array('page/create')),
                    array('label' => 'Daftar Halaman', 'url' => url('page/admin',
                                array('id' => 1))),)),
            array(
                'label' => 'User',
                'url' => array('users/admin'),
                'visible' => app()->user->isHaveAccess(),
                'items' => array(
                    array('label' => 'Tambah User', 'url' => array('users/create')),
                    array('label' => 'Daftar User', 'url' => array('users/admin')),)),
            array(
                'label' => 'Ganti Password',
                'url' => array('users/change'),),
            array(
                'label' => 'Link',
                'url' => url('link/update', array('id' => 1)),),
        );
    }

    static public function frontMenu($topPage, $recursive = false) {
        $criteria = new CDbCriteria();
        $criteria->addCondition("top_halaman = $topPage");
        $criteria->addCondition("halaman_id != 1");
        $criteria->order = 'urut_halaman';
        $pages = Page::model()->findAll($criteria);
        $ui = array();
        // $kategori_halaman=$page['page_name'];
        foreach ($pages as $page) {
            if ($page['status'] == 0) continue;
            $nama = ucwords($page['nama_halaman']);
            if ($page['kategori_halaman'] == 0) {
                $url = url('page/view',
                        array(
                    'id' => //                lang() == "id" ? $page['slug_id'] : $page['slug_en']));
                    $page['slug_id']));
            } else {
                $url = array($page['file_include']);
            }
            $items = array();
            if ($recursive) {
                $items = u::frontMenu($page['halaman_id'], $recursive);
            }
            if (count($items) > 0) {
                $ui[] = array('label' => $nama, 'url' => $url, 'items' => $items);
            } else {
                $ui[] = array('label' => $nama, 'url' => $url);
            }
        }
        return $ui;
    }

    static public function RemoveAll($dir, $patern = "*") {
        array_map('unlink', glob($dir . $patern));
    }

    static public function break_words($words, $length, $style = "") {
        $words = str_replace("<br>", " ", $words);
        $words = str_replace("<p>", "", $words);
        $words = str_replace("</p>", "", $words);
        if (strlen($words) > $length) {
            $spasi = strpos($words, " ", $length);
            $words = substr($words, 0, $spasi);
            if ($spasi == "") {
                $words = $words;
            }
        }
        if (strlen($words) < $length) {
            $words = $words;
        }
        // $words='<p '.$style.'>'.$words.'... </p>';
        return $words;
    }

    // static public function html($words,$image,$style)
    //{
    //$words='<div '.$style.'><img src="' . $image . '" width="16px" height="16px"> '.$words.'</div>';
    //return $words;
    //}
    static public function tabelkelompok($data) {
        $ketua = $data->ketua0 == null ? "-" : $data->ketua0->nama;
        $wakilketua = $data->wakilKetua == null ? "-" : $data->wakilKetua->nama;
        $imam = $data->imam0 == null ? "-" : $data->imam0->nama;
        $wakilimam1 = $data->wakilImam1 == null ? "-" : $data->$wakilimam1->nama;
        $wakilimam2 = $data->wakilImam2 == null ? "-" : $data->$wakilimam2->nama;
        $words = '';
        $words .= '<table border="0" width="100%" class="fontcolorbiru0b5fa5 font12 fontfamcalibry">';
        $words .= '<tr>';
        $words .= '<td width="30%">';
        $words .= '<div><img src="' . bu() . '/img/radio-button_off.gif" width="16px" height="16px"> ' .
                strtoupper($data['nama_kelompok']) . '</div>';
        $words .= '<div><img src="' . bu() . '/img/home.gif" width="16px" height="16px"> ' .
                $data->idKabupaten->nama_kabupaten . '</div>';
        $words .= '</td>';
        $words .= '<td width="70%">';
        $words .= '<div><img src="' . bu() . '/img/laskar.png" width="16px" height="16px"> Ketua : ' . $ketua . '</div>';
        $words .= '<div><img src="' . bu() . '/img/laskar.png" width="16px" height="16px"> Wakil Ketua :' . $wakilketua . '</div>';
        //$words .= '<div><img src="' . bu() . '/img/user_friend.gif" width="16px" height="16px"> ' . $imam . '</div>';
        //$words .= '<div><img src="' . bu() . '/img/user_friend.gif" width="16px" height="16px"> ' . $wakilimam1 . '</div>';
        //$words .='<div><img src="' . bu() . '/img/user_friend.gif" width="16px" height="16px"> ' . $wakilimam2 . '</div>';
        $words .= '</td>';
        $words .= '</tr>';
        $words .= '<tr>';
        $words .= '<td width="30%">';
        $words .= '<img src="' . bu() . '/img/time_clock.gif" width="16px" height="16px"/>Jadwal Kegiatan';
        $words .= '</td>';
        $words .= '<td width="70%">';
        $words .= '<div>' . u::show_kegiatan($data->kegiatans) . ' </div>';
        $words .= '</td>';
        $words .= '</tr>';
        $words .= '</table>';
        return $words;
    }

    static private function show_kegiatan($kegiatans) {
        if (count($kegiatans) == 0) return "-";
        $kegiatan = "";
        $detilkhusuyiah = "";
        $detilrutin = "";
        foreach ($kegiatans as $keg) {
            if ($keg->bentuk_kegiatan == 'Khusuyiah') {
                $detilkhusuyiah .= '<li>';
                $detilkhusuyiah .= '<div>Tempat     :' . $keg->tempat . '</div>';
                $detilkhusuyiah .= '<div>Waktu      :' . $keg->waktu . '</div>';
                $detilkhusuyiah .= '<div>Keterangan :' . $keg->keterangan . '</div>';
                $detilkhusuyiah .= '<div>Penceramah :' . $keg->penceramah . '</div>';
                $detilkhusuyiah .= '<div>Kontak     :' . $keg->kontak . '</div>';
                $detilkhusuyiah .= '</li>';
            } else {
                $detilrutin .= '<li>';
                $detilrutin .= '<div>Tempat     :' . $keg->tempat . '</div>';
                $detilrutin .= '<div>Waktu      :' . $keg->waktu . '</div>';
                $detilrutin .= '<div>Keterangan :' . $keg->keterangan . '</div>';
                $detilrutin .= '<div>Penceramah :' . $keg->penceramah . '</div>';
                $detilrutin .= '<div>Kontak     :' . $keg->kontak . '</div>';
                $detilrutin .= '</li>';
            }
        }

        $kegiatan .= '<div><b>Khususiyah</b></div>';
        $kegiatan .= '<ul>' . $detilkhusuyiah . '</ul>';
        $kegiatan .= '<br/><div><b>Rutiniah</b></div>';
        $kegiatan .= '<ul>' . $detilrutin . '</ul>';
        return $kegiatan;
    }

    static public function tabeljamaah($data) {
        $nama = $data["nama"] == null ? "-" : $data["nama"];
        $kelompok = $data->idKelompok == null ? "-" : $data->idKelompok->nama_kelompok;
        $kabupaten = $data->idKabupaten == null ? "-" : $data->idKabupaten->nama_kabupaten;
        $words = '';
        $words .= '<table border="0" width="100%">';
        $words .= '<tr>';
        $words .= '<td width="20%">';
        if (file_exists(Yii::getPathOfAlias('webroot') . '/img/jamaah/foto/' . $data->id_laskar . '.jpg')) {
            $words .= '<div><img src="' . bu() . '/img/jamaah/foto/' . $data->id_laskar .
                    '.jpg" width="100px" height="133px"></div>';
        } else {
            $words .= '<div><img src="' . bu() . '/img/noimages.jpg" width="100px" height="133px"></div>';
        }
        $words .= '</td>';
        $words .= '<td width="70%">';
        $words .= '<div><div style="float:left;width:70px">Nama</div><div style="float:left;width:120px"> ' . $nama .
                '</div></div><br/>';
        $words .=
                '<div><div style="float:left;width:70px">Kelompok</div><div style="float:left;width:120px">  ' . $kelompok .
                '</div></div><br/>';
        $words .= '<div><div style="float:left;width:70px">Kabupaten</div><div style="float:left;width:120px"> ' .
                $kabupaten . '</div></div>';
        $words .= '</td>';
        $words .= '</tr>';
        $words .= '</table>';
        return $words;
    }

    static public function getImage($words, $width, $height, $style = "") {
        $image = '';
        $sRegExp = "/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i";
        preg_match($sRegExp, $words, $Match);
        if (count($Match) > 0) {
            $image = $Match['1'];
            $image = str_replace(".JPG", ".jpg", $image);
        }
        if (!empty($image)) {
            $image =
                    '<img width="' . $width . '" height="' . $height . '" ' . $style . ' border="0" src="' . $image . '"/>';
        }
        return $image;
    }

    static public function getStukturOrgList() {
        global $struktur_org;
        $list = array();
        foreach ($struktur_org as $key => $node) {
            $list[$key] = $node;
        }
        return $list;
    }

    static public function getPengurusKabupaten($id) {
        $pengurus = '';
        global $penguruskabupaten;
        $list = array();
        $list = $penguruskabupaten;
        $pengurus = $list[$id];
        return $pengurus;
    }

    static public function getPengurusKecamatan($id) {
        $pengurus = '';
        global $penguruskecamatan;
        $list = array();
        $list = $penguruskecamatan;
        $pengurus = $list[$id];
        return $pengurus;
    }

    static public function getPengurusKelurahan($id) {
        $pengurus = '';
        global $penguruskelurahan;
        $list = array();
        $list = $penguruskelurahan;
        $pengurus = $list[$id];
        return $pengurus;
    }

    static public function getPengurusDesa($id) {
        $pengurus = '';
        global $pengurusdesa;
        $list = array();
        $list = $pengurusdesa;
        $pengurus = $list[$id];
        return $pengurus;
    }

    static public function autoCompleteJamaah() {
        $res = array();
        if (isset($_GET['term'])) {
            // http://www.yiiframework.com/doc/guide/database.dao
            $qtxt = "SELECT id_laskar as id,nama as value,nama as label FROM {{jamaah}} WHERE nama LIKE :username
            limit 10";
            $command = app()->db->createCommand($qtxt);
            $command->bindValue(":username", '%' . $_GET['term'] . '%',
                    PDO::PARAM_STR);
            $res = $command->queryAll();
        }
        echo CJSON::encode($res);
    }

    static public function autoCompleteJamaahKelompok($id) {
        $res = array();
        if (isset($_GET['term'])) {
            // http://www.yiiframework.com/doc/guide/database.dao
            $qtxt = "SELECT id_laskar as id,nama as value,nama as label FROM {{jamaah}}
                WHERE id_kelompok = :id AND nama LIKE :username limit 10";
            $command = app()->db->createCommand($qtxt);
            $command->bindValues(array(":id" => $id, ":username" => '%' . $_GET['term'] . '%'));
            $res = $command->queryAll();
        }
        echo CJSON::encode($res);
    }

    static public function get_model_by_id($model, $id) {
        return CActiveRecord::model($model)->findByPk($id);
    }

    static public function autoCompleteKabupaten() {
        $res = array();
        if (isset($_GET['term'])) {
            // http://www.yiiframework.com/doc/guide/database.dao
            $qtxt = "SELECT id_kabupaten as id,nama_kabupaten as value,nama_kabupaten as label
                FROM {{kabupaten}} WHERE nama_kabupaten LIKE :username
            limit 10";
            $command = app()->db->createCommand($qtxt);
            $command->bindValue(":username", '%' . $_GET['term'] . '%',
                    PDO::PARAM_STR);
            $res = $command->queryAll();
        }
        echo CJSON::encode($res);
    }

    static public function auto_complete_kelompok() {
        $res = array();
        if (isset($_GET['term'])) {
            // http://www.yiiframework.com/doc/guide/database.dao
            $qtxt = "SELECT id_kelompok as id,nama_kelompok as value,nama_kelompok as label FROM {{kelompok}} WHERE nama_kelompok LIKE :username
            limit 10";
            $command = app()->db->createCommand($qtxt);
            $command->bindValue(":username", '%' . $_GET['term'] . '%',
                    PDO::PARAM_STR);
            $res = $command->queryAll();
        }
        echo CJSON::encode($res);
    }

    static public function parent_kajian($parent_id) {
        $parent = '';
        $criteria = new CDbCriteria();
        $criteria->addCondition("id=$parent_id");
        $criteria->addCondition("kategori=1");
        //        $criteria->order = "urut_halaman";
        $parents = Kajian::model()->find($criteria);
        $parent = $parents->nama;
        return $parent;
    }

    static public function build_index() {
        $index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.runtime.search'),
                true);
        $posts = Berita::model()->findAll();
        foreach ($posts as $post) {
            $doc = new Zend_Search_Lucene_Document();
            $doc->addField(Zend_Search_Lucene_Field::Text('title',
                            CHtml::encode($post->nama), 'utf-8'));
            $doc->addField(Zend_Search_Lucene_Field::Text('link',
                            CHtml::encode(url("berita/view",
                                            array('id' => $post->id))), 'utf-8'));
            $doc->addField(Zend_Search_Lucene_Field::Text('content',
                            CHtml::encode($post->isi), 'utf-8'));
            $index->addDocument($doc);
        }
        $index->commit();
    }

    static public function get_list_kabupaten() {
        $user = oUser();
        $kode = $user->idLaskar->idKelompok->idKabupaten->kode_lokasi;
        $id = $user->idLaskar->idKelompok->id_kabupaten;
        $arr = array();
        if ($user->level == LevelUser::KABUPATEN) {
            $arr[] = $id;
        } elseif ($user->level == LevelUser::ASWIL) {
            $command = app()->db->createCommand("
                SELECT {{kabupaten}}.id_kabupaten
                FROM {{kabupaten}}
                WHERE {{kabupaten}}.kode_lokasi = :kode
            ");
            $arr = $command->queryColumn(array(':kode' => $kode));
        }
        return $arr;
    }

    static public function getKabupatenListKatFront($kode_lokasi,
            $coloumn_id = 'id_kabupaten') {
        $listparent = array();
        $criteria = new CDbCriteria();
        $criteria->order = "nama_kabupaten";
        $criteria->addInCondition('kode_lokasi', $kode_lokasi);
        $parents = Kabupaten::model()->findAll($criteria);
        foreach ($parents as $parent) {
            $listparent[$parent[$coloumn_id]] = $parent['nama_kabupaten'];
        }
        return $listparent;
    }

    static public function get_list_kabupatenKat($kode) {
        $user = oUser();
        //$kode = $user->idLaskar->idKelompok->idKabupaten->kode_lokasi;
        $id = $user->idLaskar->idKelompok->id_kabupaten;
        $arr = array();
        if ($user->level == LevelUser::KABUPATEN) {
            $arr[] = $id;
        } elseif ($user->level == LevelUser::ASWIL) {
            $command = app()->db->createCommand("
                SELECT {{kabupaten}}.id_kabupaten
                FROM {{kabupaten}}
                WHERE {{kabupaten}}.kode_lokasi in :kode
            ");
            $arr = $command->queryColumn(array(':kode' => $kode));
        }
        return $arr;
    }

    static public function get_list_kelompok() {
        $user = oUser();
        $kode = $user->idLaskar->idKelompok->idKabupaten->kode_lokasi;
        $id = $user->idLaskar->idKelompok->id_kabupaten;
        $arr = array();
        if ($user->level == LevelUser::KABUPATEN) {
            $arr[] = $id;
        } elseif ($user->level == LevelUser::ASWIL) {
            $command = app()->db->createCommand("
                SELECT {{kelompok}}.id_kelompok
                FROM {{kelompok}}
                INNER JOIN {{kabupaten}} ON {{kelompok}}.id_kabupaten = {{kabupaten}}.id_kabupaten
                WHERE {{kabupaten}}.kode_lokasi = :kode
            ");
            $arr = $command->queryColumn(array(':kode' => $kode));
        }
        return $arr;
    }

    static public function get_list_kecamatan() {
        $user = oUser();
        $id = $user->idLaskar->idKelompok->id_kabupaten;
        $arr = array();
        if ($user->level == LevelUser::KABUPATEN) {
            $command = app()->db->createCommand("
                SELECT {{kecamatan}}.id_kecamatan
                FROM {{kecamatan}}
                INNER JOIN {{kabupaten}} ON {{kecamatan}}.id_kabupaten = {{kabupaten}}.id_kabupaten
                WHERE {{kabupaten}}.id_kabupaten = :id
            ");
            $arr = $command->queryColumn(array(':id' => $id));
        } elseif ($user->level == LevelUser::ASWIL) {
            $id = u::get_list_kabupaten();
            $command = app()->db->createCommand("
                SELECT {{kecamatan}}.id_kecamatan
                FROM {{kecamatan}}
                INNER JOIN {{kabupaten}} ON {{kecamatan}}.id_kabupaten = {{kabupaten}}.id_kabupaten
                WHERE {{kabupaten}}.id_kabupaten in (:id)
            ");
            $arr = $command->queryColumn(array(':id' => implode(',', $id)));
        }
        return $arr;
    }

    static public function auto_complete_penceramah() {
        $res = array();
        if (isset($_GET['term'])) {
            // http://www.yiiframework.com/doc/guide/database.dao
            $qtxt = "SELECT DISTINCT(penceramah) as id,penceramah as value,penceramah as label
                FROM {{pengajian}}
                WHERE penceramah LIKE :username
                limit 5";
            $command = app()->db->createCommand($qtxt);
            $command->bindValue(":username", '%' . $_GET['term'] . '%',
                    PDO::PARAM_STR);
            $res = $command->queryAll();
        }
        echo CJSON::encode($res);
    }

    static public function get_list_kelurahan() {
        $user = oUser();
        $id = $user->idLaskar->idKelompok->id_kabupaten;
        $arr = array();
        if ($user->level == LevelUser::KABUPATEN) {
            $command = app()->db->createCommand("
                SELECT {{kelurahan}}.id_kelurahan
                FROM {{kelurahan}}
                INNER JOIN {{kecamatan}} ON {{kelurahan}}.id_kecamatan = {{kecamatan}}.id_kecamatan
                INNER JOIN {{kabupaten}} ON {{kecamatan}}.id_kabupaten = {{kabupaten}}.id_kabupaten
                WHERE {{kabupaten}}.id_kabupaten = :id
            ");
            $arr = $command->queryColumn(array(':id' => $id));
        } elseif ($user->level == LevelUser::ASWIL) {
            $id = u::get_list_kabupaten();
            $command = app()->db->createCommand("
                SELECT {{kelurahan}}.id_kelurahan
                FROM {{kelurahan}}
                INNER JOIN {{kecamatan}} ON {{kelurahan}}.id_kecamatan = {{kecamatan}}.id_kecamatan
                INNER JOIN {{kabupaten}} ON {{kecamatan}}.id_kabupaten = {{kabupaten}}.id_kabupaten
                WHERE {{kabupaten}}.id_kabupaten in (:id)
            ");
            $arr = $command->queryColumn(array(':id' => implode(',', $id)));
        }
        return $arr;
    }

    static public function get_list_desa() {
        $user = oUser();
        $id = $user->idLaskar->idKelompok->id_kabupaten;
        $arr = array();
        if ($user->level == LevelUser::KABUPATEN) {
            $command = app()->db->createCommand("
                SELECT {{desa}}.id_desa
                FROM {{desa}}
                INNER JOIN {{kelurahan}} ON {{desa}}.id_kelurahan = {{kelurahan}}.id_kelurahan
                INNER JOIN {{kecamatan}} ON {{kelurahan}}.id_kecamatan = {{kecamatan}}.id_kecamatan
                INNER JOIN {{kabupaten}} ON {{kecamatan}}.id_kabupaten = {{kabupaten}}.id_kabupaten
                WHERE {{kabupaten}}.id_kabupaten = :id
            ");
            $arr = $command->queryColumn(array(':id' => $id));
        } elseif ($user->level == LevelUser::ASWIL) {
            $id = u::get_list_kabupaten();
            $command = app()->db->createCommand("
                SELECT {{desa}}.id_desa
                FROM {{desa}}
                INNER JOIN {{kelurahan}} ON {{desa}}.id_kelurahan = {{kelurahan}}.id_kelurahan
                INNER JOIN {{kecamatan}} ON {{kelurahan}}.id_kecamatan = {{kecamatan}}.id_kecamatan
                INNER JOIN {{kabupaten}} ON {{kecamatan}}.id_kabupaten = {{kabupaten}}.id_kabupaten
                WHERE {{kabupaten}}.id_kabupaten in (:id)
            ");
            $arr = $command->queryColumn(array(':id' => implode(',', $id)));
        }
        return $arr;
    }

}
